module CartHelper
  def delete_good_info
    CartGood.all.each do |i|
      i.destroy if i[:count] == 0
    end
  end

  def count_total_price(total_price)
    CartGood.all.each do |i|
      total_price = total_price+ ((i.count-i.free_count)*i.price).to_f
    end
    return total_price
  end

  def update_free(i)
    CartGood.find_by_name(i.name).update(:free_count => CartGood.find_by_name(i.name)[:count] / i[:free_count]) if CartGood.find_by_name(i.name)
  end

  def update_cart_count(params)
    CartGood.find_by_id(params[:id]).update(:count => params[:count], :free_count => params[:free_count])
  end
end
